package textProcessor;

import exceptions.NoSuchFileException;
import exceptions.WrongEncodingException;

import java.io.IOException;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

        String text;
		Scanner scanner = new Scanner(System.in);
		
		while (true) {
			System.out.print("Enter input file: ");
			String inputPath = scanner.nextLine();
			try {
				text = IOManager.readTextFromFile(inputPath);
				break;
			} catch (NoSuchFileException | WrongEncodingException | IOException e) {
				System.out.println(e.getMessage());
			}
		}


		System.out.println("Processing text...");
		List<List<String>> listOfAllAnagrams = AnagramFinder.findAnagrams(text);
		System.out.println("All anagrams have been found");
		
		while (true) {
			System.out.print("Enter output file: ");
			String outputPath = scanner.nextLine();
			try {
				IOManager.saveToFile(outputPath, listOfAllAnagrams);
				break;
			} catch (NoSuchFileException | IOException e) {
				System.out.println(e.getMessage());
			}
		}
		System.out.println("Anagrams have been saved to output file");
		scanner.close();
	}
}
